﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Core;
using SmartSapce.ServiceLocation;

namespace SmartSpace.WebApp
{
    public partial class _entry : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                Application application = service.GetPersonalDefaultApplication(User.Identity.Name);
                Response.Redirect(string.Format("~/_app/{0}/_launcher.aspx?id={1}", application.Type, application.Id));
            }
            else
            {
                Guid id = new Guid(Request.QueryString["id"]);

                ICoreService service = ServiceLocator.Get<ICoreService>();

                Application application = service.GetApplication(id);
                Response.Redirect(string.Format("~/_app/{0}/_launcher.aspx?id={1}", application.Type, application.Id));
            }
        }
    }
}